<?php
$featureName = '用户';
$permission = 'member';
?>
@extends('admin.tableLayout')
@section('title',$featureName.'列表')
@section('barName',$featureName.'列表')
@section('quote')
   <form class="layui-form" >
        <label>状态：</label>
        <div class="layui-inline">
            <select name="status"  id="status" lay-search lay-filter="select">
                <option value="">全部</option>
                @foreach($status as $k=>$v)
                    <option value="{{$k}}">{{$v}}</option>
                @endforeach
            </select>

        </div>
        <div id="select" class="layui-inline"></div>

        <div class="layui-inline">
            <input type="text" class="layui-input" width="200px" id="datetime" name="searchTime" value="" placeholder="日期范围搜索">
        </div>
        <div class="layui-inline">
            <input type="text" name="searchKey" placeholder="{{$featureName}}名称" autocomplete="off" value="" class="layui-input">
        </div>
        <button lay-filter="search" class="layui-btn" id="search"><i class="fa fa-search" aria-hidden="true"></i> 查询</button>
    </form>
@endsection

@section('checkbox_btn')

@endsection
@section('toolbar')
    @can($permission)
        <a class="layui-btn layui-btn-xs" lay-event="chose">选择</a>

@endcan
@endsection
@section('tableRender')
    <script>
        layui.use(['table','jquery','form'], function(){
            var table = layui.table;
            var $=layui.jquery;
            var form=layui.form;
            var category_id=$("#category_id").val();
            var _renderLoad = layer.msg('正在查找{{$featureName}}，请稍候',{icon: 16,time:false,shade:0.8});
            var render=table.render({
                elem:"#table",
                page:true,
                id:'idTest',
                url:'{{route($routePrefix.'.Ajax')}}',
                where:{
                    searchKey:$("input[name='searchKey']").val(),
                    searchTime:$("input[name='searchTime']").val(),
                    status:$("#status").val(),
                },
                height:400,
                cols:  [[ //标题栏
                    {checkbox:true,fixed:true},
                    {field: 'id', title: 'ID', width: 80,fixed:true,sort: true}
                    ,{field: 'nickname', title: '{{$featureName}}昵称', width: 150},
                    {field:'status_name',title:'状态',width:80,sort: true},
                    //{field:'subscribe_name',title:'订阅状态',width:150,sort: true},
                    {field: 'parent_name', title: '推广人', width: 100},
                    {field:'mobile',title:'手机号',width:200},
                    {field: 'sex_name', title: '性别', width: 100,sort:true},
                    {field:'wallet_all_push_money',title:'{{config('wallet.wallet.wallet_all_push_money')}}（{{config('wallet.unit.wallet_all_push_money')}}）',width:200,sort: true},
                    {field:'wallet_used_push_money',title:'{{config('wallet.wallet.wallet_used_push_money')}}（{{config('wallet.unit.wallet_used_push_money')}}）',width:200,sort: true},
                    {field:'wallet_push_money',title:'{{config('wallet.wallet.wallet_push_money')}}（{{config('wallet.unit.wallet_push_money')}}）',width:200,sort: true},
                    {field: 'wallet_spots', title: '{{config('wallet.wallet.wallet_spots')}}({{config('wallet.unit.wallet_spots')}})', width: 200,sort: true},
                    {field: 'created_at', title: '注册时间', width: 150,sort: true},
                    {fixed: 'right', width:250,title:'操作', align:'center', toolbar: '#toolbar'}
                    //这里的toolbar值是模板元素的选择器
                ]],
                response: {//返回格式自定义
                    statusName: 'code' //数据状态的字段名称，默认：code
                    ,statusCode: 0 //成功的状态码，默认：0
                    ,msgName: 'msg' //状态信息的字段名称，默认：msg
                    ,countName: 'total' //数据总数的字段名称，默认：count
                    ,dataName: 'data' //数据列表的字段名称，默认：data
                },
                done:function () {
                    layer.close(_renderLoad);
                }
            });
            $('#search').on('click',function () {
                var data = {
                    searchKey:$("input[name='searchKey']").val(),
                    searchTime:$("input[name='searchTime']").val(),
                    status:$("#status").val(),
                };
                _renderLoad = layer.msg('正在查找{{$featureName}}，请稍候',{icon: 16,time:false,shade:0.8});
                render.reload(
                    {
                        where:data
                    }
                );
                return false;
            })
            table.on('checkbox(table)', function(obj){
                //console.log(obj)
            });


            table.on('tool(table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                 if(layEvent === 'chose'){ //编辑
                     parent.combo = data;
                     console.log(data)
                     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                     parent.layer.close(index); //再执行关闭                       //do something
                     //同步更新缓存对应的值
                 }
            });
        });
    </script>
@endsection

